//
//  CreatStochasticOrderNumber.m
//  EasyToTesco2.0
//
//  Created by knew on 16/9/11.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "CreatStochasticOrderNumber.h"

@implementation CreatStochasticOrderNumber

+ (NSString *)CreatStochasticOrderNumberWithPayTypeString:(NSString *)TypeString {
    
    NSDate *localDate = [NSDate date];
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[localDate timeIntervalSince1970]];
    NSLog(@"timeSp:%@",timeSp);

    static int kNumber = 4;
    NSString *sourceStr = @"0123456789";
    NSMutableString *stochasticNumber = [[NSMutableString alloc] init];
    srand((unsigned)time(0));
    for (int i = 0; i < kNumber; i++)
    {
        unsigned index = rand() % [sourceStr length];
        NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
        [stochasticNumber appendString:oneStr];
    }
    
    return [NSString stringWithFormat:@"%@%@%@",TypeString,timeSp,stochasticNumber];
    
}

+ (NSString *)DataStringWithOrderNumber:(NSString *)orderNumber {
//    double unixTimeStamp = 1476413170;
    NSString *unixString = [orderNumber substringWithRange:NSMakeRange(2, 10)];
    double unixTimeStamp = unixString.doubleValue;
    NSTimeInterval _interval=unixTimeStamp;
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
    NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
    [_formatter setLocale:[NSLocale currentLocale]];
    [_formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *_date=[_formatter stringFromDate:date];
    NSLog(@"%@",_date);
    return _date;
}

@end
